<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./template.xhtml">

            <ui:define name="title">
                Gợi ý dịch vụ
            </ui:define>

            <ui:define name="content">
                <h:form id="inputForm" prependId="false">
                    <h:panelGrid columns="2">
                        Dịch vụ*
                        <p:inputText value="#{serviceSuggestionBean.selected.serviceSyntax}"
                                     required="true" requiredMessage="Bạn chưa nhập dịch vụ"/>

                        Tham số
                        <p:inputText value="#{serviceSuggestionBean.selected.param}"/>

                        Nội dung gợi ý*
                        <p:inputTextarea value="#{serviceSuggestionBean.selected.helpContent}"
                                         required="true" requiredMessage="Bạn chưa nhập nội dung gợi ý"
                                         onkeyup="countContentChar(this, 'suggestCharCnt'); createShortSuggestion(this)"/>
                        <h:outputText/>
                        <h:panelGrid>
                            <span id="suggestCharCnt">Tin 1: 0 ký tự</span>
                        </h:panelGrid>
                        <br/>
                        Gợi ý ngắn*
                        <p:inputText id="shortSuggestion" value="#{serviceSuggestionBean.selected.shortHelpContent}" size="60"
                                         required="true" requiredMessage="Bạn chưa nhập gợi ý ngắn"/>
                        <f:facet name="footer">  
                            <p:commandButton ajax="false" value="Thêm mới" rendered="#{!serviceSuggestionBean.edit}" action="#{serviceSuggestionBean.create()}"/>
                            <p:commandButton ajax="false" value="Cập nhật" rendered="#{serviceSuggestionBean.edit}" action="#{serviceSuggestionBean.edit()}"/>
                            <p:commandButton ajax="false" value="Hủy bỏ" immediate="true" action="#{serviceSuggestionBean.resetToCreateForm()}"/>
                        </f:facet>
                    </h:panelGrid>
                </h:form>

                <br/>

                <h:form>

                    <p:dataTable id="table" value="#{serviceSuggestionBean.list}" var="item" paginator="#{serviceSuggestionBean.list.size() >20}" rows="20" 
                                 selection="#{serviceSuggestionBean.selectedList}" selectionMode="multiple" resizableColumns="true">

                        <f:facet name="header">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{serviceSuggestionBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="DeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <f:facet name="footer">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{serviceSuggestionBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="DeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <p:column headerText="Dịch vụ" sortBy="#{item.serviceSyntax}">
                            #{item.serviceSyntax}
                        </p:column>
                        <p:column headerText="Tham số" sortBy="#{item.param}">
                            #{item.param}
                        </p:column>
                        <p:column headerText="Nội dung gợi ý" sortBy="#{item.helpContent}">
                            #{item.helpContent}
                        </p:column>
                        <p:column headerText="Gợi ý ngắn" sortBy="#{item.shortHelpContent}">
                            #{item.shortHelpContent}
                        </p:column>
                    </p:dataTable>

                    <p:confirmDialog message="Bạn muốn xóa các bản ghi đã chọn?"  
                                     header="Xác nhận" severity="alert" widgetVar="DeleteConfirm">  

                        <p:commandButton update="table" value="Có" oncomplete="DeleteConfirm.hide()"  
                                         action="#{serviceSuggestionBean.remove()}"/>
                        <p:commandButton value="Không" onclick="DeleteConfirm.hide()" type="button" />   

                    </p:confirmDialog>

                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
